using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Commerce.Common
{
	/// <summary>
	/// Strongly-typed collection for the IntegrationAddress class.
	/// </summary>
	[Serializable]
	public partial class IntegrationAddressCollection : ActiveList<IntegrationAddress, IntegrationAddressCollection> 
	{	   
		public IntegrationAddressCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the IntegrationAddress table.
	/// </summary>
	[Serializable]
	public partial class IntegrationAddress : ActiveRecord<IntegrationAddress>
	{
		#region .ctors and Default Settings
		
		public IntegrationAddress()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public IntegrationAddress(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

		public IntegrationAddress(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public IntegrationAddress(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor
		public static Query CreateQuery() { return new Query(Schema); }

		
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("IntegrationAddress", TableType.Table, DataService.GetInstance("dashCommerce"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarAddressId = new TableSchema.TableColumn(schema);
				colvarAddressId.ColumnName = "addressId";
				colvarAddressId.DataType = DbType.Int32;
				colvarAddressId.MaxLength = 0;
				colvarAddressId.AutoIncrement = true;
				colvarAddressId.IsNullable = false;
				colvarAddressId.IsPrimaryKey = true;
				colvarAddressId.IsForeignKey = false;
				colvarAddressId.IsReadOnly = false;
				colvarAddressId.DefaultSetting = @"";
				colvarAddressId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAddressId);
				
				TableSchema.TableColumn colvarOrderId = new TableSchema.TableColumn(schema);
				colvarOrderId.ColumnName = "orderId";
				colvarOrderId.DataType = DbType.Int32;
				colvarOrderId.MaxLength = 0;
				colvarOrderId.AutoIncrement = false;
				colvarOrderId.IsNullable = true;
				colvarOrderId.IsPrimaryKey = false;
				colvarOrderId.IsForeignKey = true;
				colvarOrderId.IsReadOnly = false;
				colvarOrderId.DefaultSetting = @"";
				
					colvarOrderId.ForeignKeyTableName = "CSK_Store_Order";
				schema.Columns.Add(colvarOrderId);
				
				TableSchema.TableColumn colvarAddressType = new TableSchema.TableColumn(schema);
				colvarAddressType.ColumnName = "addressType";
				colvarAddressType.DataType = DbType.String;
				colvarAddressType.MaxLength = 10;
				colvarAddressType.AutoIncrement = false;
				colvarAddressType.IsNullable = true;
				colvarAddressType.IsPrimaryKey = false;
				colvarAddressType.IsForeignKey = false;
				colvarAddressType.IsReadOnly = false;
				colvarAddressType.DefaultSetting = @"";
				colvarAddressType.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAddressType);
				
				TableSchema.TableColumn colvarFirstName = new TableSchema.TableColumn(schema);
				colvarFirstName.ColumnName = "firstName";
				colvarFirstName.DataType = DbType.String;
				colvarFirstName.MaxLength = 250;
				colvarFirstName.AutoIncrement = false;
				colvarFirstName.IsNullable = true;
				colvarFirstName.IsPrimaryKey = false;
				colvarFirstName.IsForeignKey = false;
				colvarFirstName.IsReadOnly = false;
				colvarFirstName.DefaultSetting = @"";
				colvarFirstName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarFirstName);
				
				TableSchema.TableColumn colvarLastName = new TableSchema.TableColumn(schema);
				colvarLastName.ColumnName = "lastName";
				colvarLastName.DataType = DbType.String;
				colvarLastName.MaxLength = 250;
				colvarLastName.AutoIncrement = false;
				colvarLastName.IsNullable = true;
				colvarLastName.IsPrimaryKey = false;
				colvarLastName.IsForeignKey = false;
				colvarLastName.IsReadOnly = false;
				colvarLastName.DefaultSetting = @"";
				colvarLastName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarLastName);
				
				TableSchema.TableColumn colvarEmail = new TableSchema.TableColumn(schema);
				colvarEmail.ColumnName = "email";
				colvarEmail.DataType = DbType.String;
				colvarEmail.MaxLength = 250;
				colvarEmail.AutoIncrement = false;
				colvarEmail.IsNullable = true;
				colvarEmail.IsPrimaryKey = false;
				colvarEmail.IsForeignKey = false;
				colvarEmail.IsReadOnly = false;
				colvarEmail.DefaultSetting = @"";
				colvarEmail.ForeignKeyTableName = "";
				schema.Columns.Add(colvarEmail);
				
				TableSchema.TableColumn colvarAddress1 = new TableSchema.TableColumn(schema);
				colvarAddress1.ColumnName = "address1";
				colvarAddress1.DataType = DbType.String;
				colvarAddress1.MaxLength = 40;
				colvarAddress1.AutoIncrement = false;
				colvarAddress1.IsNullable = true;
				colvarAddress1.IsPrimaryKey = false;
				colvarAddress1.IsForeignKey = false;
				colvarAddress1.IsReadOnly = false;
				colvarAddress1.DefaultSetting = @"";
				colvarAddress1.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAddress1);
				
				TableSchema.TableColumn colvarAddress2 = new TableSchema.TableColumn(schema);
				colvarAddress2.ColumnName = "address2";
				colvarAddress2.DataType = DbType.String;
				colvarAddress2.MaxLength = 40;
				colvarAddress2.AutoIncrement = false;
				colvarAddress2.IsNullable = true;
				colvarAddress2.IsPrimaryKey = false;
				colvarAddress2.IsForeignKey = false;
				colvarAddress2.IsReadOnly = false;
				colvarAddress2.DefaultSetting = @"";
				colvarAddress2.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAddress2);
				
				TableSchema.TableColumn colvarCity = new TableSchema.TableColumn(schema);
				colvarCity.ColumnName = "city";
				colvarCity.DataType = DbType.String;
				colvarCity.MaxLength = 25;
				colvarCity.AutoIncrement = false;
				colvarCity.IsNullable = true;
				colvarCity.IsPrimaryKey = false;
				colvarCity.IsForeignKey = false;
				colvarCity.IsReadOnly = false;
				colvarCity.DefaultSetting = @"";
				colvarCity.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCity);
				
				TableSchema.TableColumn colvarState = new TableSchema.TableColumn(schema);
				colvarState.ColumnName = "state";
				colvarState.DataType = DbType.String;
				colvarState.MaxLength = 3;
				colvarState.AutoIncrement = false;
				colvarState.IsNullable = true;
				colvarState.IsPrimaryKey = false;
				colvarState.IsForeignKey = false;
				colvarState.IsReadOnly = false;
				colvarState.DefaultSetting = @"";
				colvarState.ForeignKeyTableName = "";
				schema.Columns.Add(colvarState);
				
				TableSchema.TableColumn colvarZip = new TableSchema.TableColumn(schema);
				colvarZip.ColumnName = "zip";
				colvarZip.DataType = DbType.String;
				colvarZip.MaxLength = 12;
				colvarZip.AutoIncrement = false;
				colvarZip.IsNullable = true;
				colvarZip.IsPrimaryKey = false;
				colvarZip.IsForeignKey = false;
				colvarZip.IsReadOnly = false;
				colvarZip.DefaultSetting = @"";
				colvarZip.ForeignKeyTableName = "";
				schema.Columns.Add(colvarZip);
				
				TableSchema.TableColumn colvarCountry = new TableSchema.TableColumn(schema);
				colvarCountry.ColumnName = "country";
				colvarCountry.DataType = DbType.String;
				colvarCountry.MaxLength = 3;
				colvarCountry.AutoIncrement = false;
				colvarCountry.IsNullable = true;
				colvarCountry.IsPrimaryKey = false;
				colvarCountry.IsForeignKey = false;
				colvarCountry.IsReadOnly = false;
				colvarCountry.DefaultSetting = @"";
				colvarCountry.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCountry);
				
				TableSchema.TableColumn colvarPhone = new TableSchema.TableColumn(schema);
				colvarPhone.ColumnName = "phone";
				colvarPhone.DataType = DbType.String;
				colvarPhone.MaxLength = 25;
				colvarPhone.AutoIncrement = false;
				colvarPhone.IsNullable = true;
				colvarPhone.IsPrimaryKey = false;
				colvarPhone.IsForeignKey = false;
				colvarPhone.IsReadOnly = false;
				colvarPhone.DefaultSetting = @"";
				colvarPhone.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPhone);
				
				TableSchema.TableColumn colvarCreatedOn = new TableSchema.TableColumn(schema);
				colvarCreatedOn.ColumnName = "createdOn";
				colvarCreatedOn.DataType = DbType.DateTime;
				colvarCreatedOn.MaxLength = 0;
				colvarCreatedOn.AutoIncrement = false;
				colvarCreatedOn.IsNullable = true;
				colvarCreatedOn.IsPrimaryKey = false;
				colvarCreatedOn.IsForeignKey = false;
				colvarCreatedOn.IsReadOnly = false;
				
						colvarCreatedOn.DefaultSetting = @"(getdate())";
				colvarCreatedOn.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreatedOn);
				
				TableSchema.TableColumn colvarCreatedBy = new TableSchema.TableColumn(schema);
				colvarCreatedBy.ColumnName = "createdBy";
				colvarCreatedBy.DataType = DbType.String;
				colvarCreatedBy.MaxLength = 50;
				colvarCreatedBy.AutoIncrement = false;
				colvarCreatedBy.IsNullable = true;
				colvarCreatedBy.IsPrimaryKey = false;
				colvarCreatedBy.IsForeignKey = false;
				colvarCreatedBy.IsReadOnly = false;
				colvarCreatedBy.DefaultSetting = @"";
				colvarCreatedBy.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreatedBy);
				
				TableSchema.TableColumn colvarModifiedOn = new TableSchema.TableColumn(schema);
				colvarModifiedOn.ColumnName = "modifiedOn";
				colvarModifiedOn.DataType = DbType.DateTime;
				colvarModifiedOn.MaxLength = 0;
				colvarModifiedOn.AutoIncrement = false;
				colvarModifiedOn.IsNullable = true;
				colvarModifiedOn.IsPrimaryKey = false;
				colvarModifiedOn.IsForeignKey = false;
				colvarModifiedOn.IsReadOnly = false;
				
						colvarModifiedOn.DefaultSetting = @"(getdate())";
				colvarModifiedOn.ForeignKeyTableName = "";
				schema.Columns.Add(colvarModifiedOn);
				
				TableSchema.TableColumn colvarModifiedBy = new TableSchema.TableColumn(schema);
				colvarModifiedBy.ColumnName = "modifiedBy";
				colvarModifiedBy.DataType = DbType.String;
				colvarModifiedBy.MaxLength = 50;
				colvarModifiedBy.AutoIncrement = false;
				colvarModifiedBy.IsNullable = true;
				colvarModifiedBy.IsPrimaryKey = false;
				colvarModifiedBy.IsForeignKey = false;
				colvarModifiedBy.IsReadOnly = false;
				colvarModifiedBy.DefaultSetting = @"";
				colvarModifiedBy.ForeignKeyTableName = "";
				schema.Columns.Add(colvarModifiedBy);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["dashCommerce"].AddSchema("IntegrationAddress",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("AddressId")]
		public int AddressId 
		{
			get { return GetColumnValue<int>("addressId"); }

			set { SetColumnValue("addressId", value); }

		}

		  
		[XmlAttribute("OrderId")]
		public int? OrderId 
		{
			get { return GetColumnValue<int?>("orderId"); }

			set { SetColumnValue("orderId", value); }

		}

		  
		[XmlAttribute("AddressType")]
		public string AddressType 
		{
			get { return GetColumnValue<string>("addressType"); }

			set { SetColumnValue("addressType", value); }

		}

		  
		[XmlAttribute("FirstName")]
		public string FirstName 
		{
			get { return GetColumnValue<string>("firstName"); }

			set { SetColumnValue("firstName", value); }

		}

		  
		[XmlAttribute("LastName")]
		public string LastName 
		{
			get { return GetColumnValue<string>("lastName"); }

			set { SetColumnValue("lastName", value); }

		}

		  
		[XmlAttribute("Email")]
		public string Email 
		{
			get { return GetColumnValue<string>("email"); }

			set { SetColumnValue("email", value); }

		}

		  
		[XmlAttribute("Address1")]
		public string Address1 
		{
			get { return GetColumnValue<string>("address1"); }

			set { SetColumnValue("address1", value); }

		}

		  
		[XmlAttribute("Address2")]
		public string Address2 
		{
			get { return GetColumnValue<string>("address2"); }

			set { SetColumnValue("address2", value); }

		}

		  
		[XmlAttribute("City")]
		public string City 
		{
			get { return GetColumnValue<string>("city"); }

			set { SetColumnValue("city", value); }

		}

		  
		[XmlAttribute("State")]
		public string State 
		{
			get { return GetColumnValue<string>("state"); }

			set { SetColumnValue("state", value); }

		}

		  
		[XmlAttribute("Zip")]
		public string Zip 
		{
			get { return GetColumnValue<string>("zip"); }

			set { SetColumnValue("zip", value); }

		}

		  
		[XmlAttribute("Country")]
		public string Country 
		{
			get { return GetColumnValue<string>("country"); }

			set { SetColumnValue("country", value); }

		}

		  
		[XmlAttribute("Phone")]
		public string Phone 
		{
			get { return GetColumnValue<string>("phone"); }

			set { SetColumnValue("phone", value); }

		}

		  
		[XmlAttribute("CreatedOn")]
		public DateTime? CreatedOn 
		{
			get { return GetColumnValue<DateTime?>("createdOn"); }

			set { SetColumnValue("createdOn", value); }

		}

		  
		[XmlAttribute("CreatedBy")]
		public string CreatedBy 
		{
			get { return GetColumnValue<string>("createdBy"); }

			set { SetColumnValue("createdBy", value); }

		}

		  
		[XmlAttribute("ModifiedOn")]
		public DateTime? ModifiedOn 
		{
			get { return GetColumnValue<DateTime?>("modifiedOn"); }

			set { SetColumnValue("modifiedOn", value); }

		}

		  
		[XmlAttribute("ModifiedBy")]
		public string ModifiedBy 
		{
			get { return GetColumnValue<string>("modifiedBy"); }

			set { SetColumnValue("modifiedBy", value); }

		}

		
		#endregion
		
		
			
		
		#region ForeignKey Properties
		
		/// <summary>
		/// Returns a CskStoreOrder ActiveRecord object related to this IntegrationAddress
		/// 
		/// </summary>
		public Commerce.Common.Order CskStoreOrder
		{
			get { return Commerce.Common.Order.FetchByID(this.OrderId); }

			set { SetColumnValue("orderId", value.OrderID); }

		}

		
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(int? varOrderId,string varAddressType,string varFirstName,string varLastName,string varEmail,string varAddress1,string varAddress2,string varCity,string varState,string varZip,string varCountry,string varPhone,DateTime? varCreatedOn,string varCreatedBy,DateTime? varModifiedOn,string varModifiedBy)
		{
			IntegrationAddress item = new IntegrationAddress();
			
			item.OrderId = varOrderId;
			
			item.AddressType = varAddressType;
			
			item.FirstName = varFirstName;
			
			item.LastName = varLastName;
			
			item.Email = varEmail;
			
			item.Address1 = varAddress1;
			
			item.Address2 = varAddress2;
			
			item.City = varCity;
			
			item.State = varState;
			
			item.Zip = varZip;
			
			item.Country = varCountry;
			
			item.Phone = varPhone;
			
			item.CreatedOn = varCreatedOn;
			
			item.CreatedBy = varCreatedBy;
			
			item.ModifiedOn = varModifiedOn;
			
			item.ModifiedBy = varModifiedBy;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varAddressId,int? varOrderId,string varAddressType,string varFirstName,string varLastName,string varEmail,string varAddress1,string varAddress2,string varCity,string varState,string varZip,string varCountry,string varPhone,DateTime? varCreatedOn,string varCreatedBy,DateTime? varModifiedOn,string varModifiedBy)
		{
			IntegrationAddress item = new IntegrationAddress();
			
				item.AddressId = varAddressId;
				
				item.OrderId = varOrderId;
				
				item.AddressType = varAddressType;
				
				item.FirstName = varFirstName;
				
				item.LastName = varLastName;
				
				item.Email = varEmail;
				
				item.Address1 = varAddress1;
				
				item.Address2 = varAddress2;
				
				item.City = varCity;
				
				item.State = varState;
				
				item.Zip = varZip;
				
				item.Country = varCountry;
				
				item.Phone = varPhone;
				
				item.CreatedOn = varCreatedOn;
				
				item.CreatedBy = varCreatedBy;
				
				item.ModifiedOn = varModifiedOn;
				
				item.ModifiedBy = varModifiedBy;
				
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string AddressId = @"addressId";
			 public static string OrderId = @"orderId";
			 public static string AddressType = @"addressType";
			 public static string FirstName = @"firstName";
			 public static string LastName = @"lastName";
			 public static string Email = @"email";
			 public static string Address1 = @"address1";
			 public static string Address2 = @"address2";
			 public static string City = @"city";
			 public static string State = @"state";
			 public static string Zip = @"zip";
			 public static string Country = @"country";
			 public static string Phone = @"phone";
			 public static string CreatedOn = @"createdOn";
			 public static string CreatedBy = @"createdBy";
			 public static string ModifiedOn = @"modifiedOn";
			 public static string ModifiedBy = @"modifiedBy";
						
		}

		#endregion
	}

}

